package com.example.datasync.service.impl;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.example.datasync.service.UserService;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author Administrator
 */
@Service
public class UserServiceImpl implements UserService {

    private final JdbcTemplate jdbcTemplate;

    public UserServiceImpl(JdbcTemplate jdbcTemplate) {
        this.jdbcTemplate = jdbcTemplate;
    }

    /**
     * 查询用户信息
     *
     * @return
     */
    @Override
    @DS("slave_1")
    public List selectUser(String id) {
        return jdbcTemplate.queryForList("select * from uc_user where id = " + id);
    }

    /**
     * 更新用户组织
     *
     * @return
     */
    @Override
    @DS("slave_1")
    public int updateOrgId(String orgId, String userId) {
        return jdbcTemplate.update("update  uc_user set org_id = " + orgId + " where id = " + userId);
    }

    /**
     * 更新电话记录
     *
     * @return
     */
    @Override
    @DS("master")
    public int updateRecord(String orgId, String userId) {
        return jdbcTemplate.update("update  phone_record set org_id = " + orgId + " where user_id = " + userId);
    }

    /**
     * 获取全部电话记录
     *
     * @return
     */
    @Override
    @DS("master")
    public List selectAllRecord() {
        return jdbcTemplate.queryForList("select * from phone_record");
    }
}